
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>新建奖惩信息</title>
    <link rel="stylesheet" href="/lib/pagination/style/pagination.css">
    <link rel="stylesheet" href="/css/base/base.css?20201106.1">
    <link rel="stylesheet" href="/css/notice/noticeManagement.css">
    <link rel="stylesheet" href="/lib/laydate/need/laydate.css">
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="/js/common/language.js"></script>
    <script src="/js/jquery/jquery.cookie.js"></script>
    <script src="/js/base/base.js"></script>
    <script src="/lib/laydate/laydate.js"></script>
    <script src="/lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/ueditor/ueditor.config.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/ueditor/ueditor.all.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../lib/layer/layer.js?20201106"></script>
    <%--<script src="../js/jquery/jquery.cookie.js"></script>--%>
    <script src="/lib/jquery.form.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/commonTheme/${sessionScope.InterfaceModel}/commonTheme.css"/>
    <style>

        input{
            float: none;
        }
        .editAndDelete3{
            color: red;
        }
        .bar {
            height: 18px;
            background: green;
        }
        select{
            width: 228px !important;
            padding-left: 10px;
        }
    </style>
    <script src="/lib/ueditor/UEcontroller.js" type="text/javascript" charset="utf-8"></script>

    <script>

    </script>
</head>
<body>
<div class="navigation">
    <img src="/img/commonTheme/${sessionScope.InterfaceModel}/newsManages2_1.png" alt="">
    <h2>新建奖惩信息</h2>

</div>
<div id="pagediv" class="tableMain">
    <%--<form id="ajaxform" action="/Hr/Incentive/addHrIncentive">--%>
        <table>
            <tbody>

            <tr>
                <td class="blue_text" width="20%">
                    <p >单位员工：</p>
                </td>
                <td width="80%" style="text-align: left">
                    <textarea name="" class="theControlData" readonly="readonly" id="personnel" style="width: 30%;" rows="5"></textarea>
                    <a style="margin-left:5px;" href="javascript:;" class="addControls" data-type="3"><fmt:message code="global.lang.add"/></a>
                    <a href="javascript:;" class="cleardate"><fmt:message code="global.lang.empty"/></a>
                </td>
            </tr>
            <tr>
                <td class="blue_text" width="20%">
                    奖惩项目：
                </td>
                <td width="80%" style="text-align: left">
                    <select id="incentiveItem">
                        <option value="">项目名称</option>
                        <option value="积极参加工作">积极参加工作</option>
                        <option value="不迟到不早退">不迟到不早退</option>
                        <option value="违规操作">违规操作</option>
                        <option value="经常迟到早退">经常迟到早退</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="blue_text" width="20%">
                    奖惩日期：
                </td>
                <td width="80%" style="text-align: left">
                    <input style="width: 228px" type="text" name="incentiveTime" readonly="readonly" onclick="laydate({format: 'YYYY-MM-DD'})">
                </td>
            </tr>
            <tr>
                <td class="blue_text" width="20%">
                    工资月份：
                </td>
                <td width="80%" style="text-align: left">
                    <input style="width: 228px" type="text" name="salaryMonth">
                </td>
            </tr>
            <tr>
                <td width="20%" class="blue_text">
                    奖惩属性
                </td>
                <td width="80%" style="text-align: left">
                    <select id="incentiveType">
                        <option value="">请选择</option>
                        <option value="奖励">奖励</option>
                        <option value="惩罚">惩罚</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="blue_text" width="20%">
                    奖惩金额：
                </td>
                <td width="80%" style="text-align: left">
                    <input style="width: 228px" type="text" name="incentiveAmount">
                </td>
            </tr>
            <tr>
                <td class="blue_text" width="20%">
                    备注：
                </td>
                <td width="80%" style="text-align: left">
                    <textarea name="remark" id="remark" rows="5" style="background: #fff;width: 30%;"></textarea>
                </td>
            </tr>
            <tr>
                <td class="blue_text" width="20%">
                    附件文档：
                </td>
                <td width="80%" class="files" id="files_txt">
                </td>
            </tr>
            <tr>
                <td class="blue_text" width="20%">
                    附件上传：
                </td>
                <td width="80%" style="text-align: left">
                    <form id="uploadimgform" style="float: left;" target="uploadiframe"  action="/upload?module=INCENTIVE"  method="post" >
                        <input type="file" multiple="multiple" name="file"  id="uploadinputimg"  class="w-icon5" style="position: absolute;opacity: 0;width: 70px;filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0)">
                        <a href="#" id="uploadimg"><img style="margin-right:5px;" src="/img/icon_uplod.png"/><fmt:message code="global.th.fileup" /></a>
                    </form>
                    <div id="progress" style="width: 200px;float: left;margin-left: 10px;margin-top: 2px;">
                        <div class="bar" style="width: 0%;"></div>
                    </div>
                    <div class="barText" style="float: left;margin-left: 10px;"></div>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="padding: 5px;">
                    奖惩说明：
                    <div id="word_container" name="incentiveDescription">

                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center" class="btnarr">
                    <a href="javascript:;" class="savebtn"><fmt:message code="global.lang.save"/></a>
                </td>
            </tr>
            </tbody>
        </table>
    <%--</form>--%>
</div>
<script>

    var user_id='';
    ue = UE.getEditor('word_container',{elementPathEnabled : false});
    UEimgfuc();
    var inDataId=GetQueryString('dataid')
$(function () {
    $('input[name="salaryMonth"]').val(queryTime());
    var timer=null;
    $('#uploadinputimg').fileupload({
        dataType:'json',
        progressall: function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $('#progress .bar').css(
                'width',
                progress + '%'
            );
            $('.barText').html(progress + '%');
            if(progress >= 100){
                timer=setTimeout(function () {
                    $('#progress .bar').css(
                        'width',
                        0 + '%'
                    );
                    $('.barText').html('');
                },2000);

            }
        },
        done: function (e, data) {
            if(data.result.obj != ''){
                var data = data.result.obj;
                var str = '';
                var str1 = '';
                for (var i = 0; i < data.length; i++) {
                    var gs = data[i].attachName.split('.')[1];
                    if(gs == 'jsp'||gs == 'css'||gs == 'js'||gs == 'html'||gs == 'java'||gs == 'php' ){
                        str += '';
                        layer.alert('jsp、css、js、html、java文件禁止上传!',{},function(){
                            layer.closeAll();
                        });
                    }else{
                        str += '<div class="dech" deUrl="' + encodeURI(data[i].attUrl)+ '"><a href="<%=basePath %>download?'+encodeURI(data[i].attUrl)+'" NAME="' + data[i].attachName + '*"><img style="margin-right:10px;" src="/img/attachment_icon.png"/>' + data[i].attachName + '</a><img class="deImgs" style="margin-left:5px;cursor: pointer;" src="/img/file/icon_deletecha_03.png"/><input type="hidden" class="inHidden" value="' + data[i].aid + '@' + data[i].ym + '_' + data[i].attachId + ',"></div>';
                    }
                }
                $('#files_txt').append(str);
            }else{
                layer.alert('添加附件大小不能为空!',{},function(){
                    layer.closeAll();
                });
            }
        }
    });

    //附件删除
    $('#files_txt').on('click','.deImgs',function(){
        var data=$(this).parents('.dech').attr('deUrl');
        var dome=$(this).parents('.dech');
        deleteChatment(data,dome);
    })

    $('.addControls').click(function () {
        user_id='personnel';
        $.popWindow("/common/selectUser");
    })
    $('.cleardate').click(function () {
        $('#personnel').attr('username','');
        $('#personnel').attr('dataid','');
        $('#personnel').attr('user_id','');
        $('#personnel').attr('userprivname','');
        $('#personnel').val('');
    })

    if(inDataId != '' && inDataId != undefined){
        $.ajax({
            type:'get',
            url:'',
            dataType:'json',
            data:{
                incentiveId:inDataId
            },
            success:function (res) {
                var datas=res.object;
                $('#personnel').val(datas.userName+',');
                $('#personnel').attr('user_id',datas.staffName+',');
                $('#incentiveItem').val(datas.incentiveItem);
                $('input[name="incentiveTime"]').val(datas.incentiveTime)
                $('input[name="salaryMonth"]').val(datas.salaryMonth)
                $('#incentiveType').val(datas.incentiveType);
                $('input[name="incentiveAmount"]').val(datas.incentiveAmount)
                $('#remark').val(datas.remark);
                ue.setContent(datas.incentiveDescription);
            }
        })
    }

    $('.savebtn').click(function () {
        var html = ue.getContent();
        var attachId='';
        var attachName='';
        for(var i=0;i<$('#files_txt .inHidden').length;i++){
            attachId+=$('#files_txt .inHidden').eq(i).val();
            attachName+=$('#files_txt a').eq(i).attr('NAME');
        }
        $.ajax({
            type:'post',
            url:'',
            dataType:'json',
            data:{
                staffName:$('#personnel').attr('user_id'),
                incentiveItem:$('#incentiveItem option:selected').val(),
                incentiveTime:$('input[name="incentiveTime"]').val(),
                salaryMonth:$('input[name="salaryMonth"]').val(),
                incentiveAmount:$('input[name="incentiveAmount"]').val(),
                incentiveType:$('#incentiveType option:selected').val(),
                remark:$('#remark').val(),
                attachmentId:attachId,
                attachmentName:attachName,
                incentiveDescription:html
            },
            success:function (res) {
                if(res.flag){
                    $.layerMsg({content: '保存成功！', icon: 1}, function () {
                        parent.$('[name="notices"]').attr('src','/Hr/Incentive/bonpenManage')
                        parent.$('.head-top ul li').removeClass('active')
                        $((parent.$('.head-top ul li'))[0]).addClass('active')
                    });
                }else {
                    $.layerMsg({content:'保存失败！', icon: 2});
                }
            }
        })
    })

})

    //删除附件
    function deleteChatment(data,element){

        layer.confirm('<fmt:message code="workflow.th.que" />？', {
            btn: ['<fmt:message code="global.lang.ok" />','<fmt:message code="depatement.th.quxiao" />'], //按钮
            title:"<fmt:message code="notice.th.DeleteAttachment" />"
        }, function(){
            //确定删除，调接口
            $.ajax({
                type:'get',
                url:'/delete',
                dataType:'json',
                data:data,
                success:function(res){

                    if(res.flag == true){
                        layer.msg('<fmt:message code="workflow.th.delsucess" />', { icon:6});
                        element.remove();
                    }else{
                        layer.msg('<fmt:message code="lang.th.deleSucess" />', { icon:6});
                    }
                }
            });

        }, function(){
            layer.closeAll();
        });
    }

    function queryTime(){
        function p(s) {
            return s < 10 ? '0' + s: s;
        }
        var myDate = new Date();
        //获取当前年
        var year=myDate.getFullYear();
        //获取当前月
        var month=myDate.getMonth()+1;
        //获取当前日
        var date=myDate.getDate();
        var h=myDate.getHours();       //获取当前小时数(0-23)
        var m=myDate.getMinutes();     //获取当前分钟数(0-59)
        var s=myDate.getSeconds();
//        var now=year+'-'+p(month)+"-"+p(date)+" "+p(h)+':'+p(m)+":"+p(s);
        var now=year+'-'+p(month);
//        if(type==undefined){
//            return now;
//        }else {
//            return year+'-'+p(month)+"-"+p(date)
//        }
        return now;


    }

    // 用正则表达式获取地址栏参数
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);

        if(r!=null) {
            return  unescape(r[2]);
        } else {
            return null;
        }
    }

</script>
</body>
</html>